package com.example.education.Controller;


import com.example.education.Bean.ForeignSubjects;
import com.example.education.Bean.packaginggroup.PackagingString;
import com.example.education.Mapper.ForeignSubjectsMapper;
import com.example.education.service.impl.ForeignSubjectsServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.Cacheable;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 姚
 * @since 2023-03-27
 */
@RestController
@RequestMapping("/foreignsubjects")
@CrossOrigin
public class ForeignSubjectsController {
    @Autowired
    private ForeignSubjectsMapper foreignSubjectsMapper;
    @Autowired
    private ForeignSubjectsServiceImpl foreignSubjectsService;


    @PostMapping
    public Integer save(@RequestBody(required = false) ForeignSubjects foreignSubjects) {//将传回来的json对象转

        return foreignSubjectsService.insert(foreignSubjects);
    }

    //根据传来的学校名字查询所有课程
    @PostMapping("/select")
    @Cacheable(value = "foreignSubjects")
    public ForeignSubjects[] select(@RequestBody(required = false) PackagingString packageString) {
        ForeignSubjects[] foreignSubjects = foreignSubjectsService.select(packageString.getString());
        System.out.println(foreignSubjects);
        return foreignSubjects;
    }

}



